package com.wn.icloud.provider.uac.rpc;

import com.wn.icloud.common.authority.PermissionInfo;
import com.wn.icloud.common.msg.TableResultResponse;
import com.wn.icloud.common.util.user.JwtAuthenticationRequest;
import com.wn.icloud.common.vo.user.UserInfo;
import com.wn.icloud.provider.uac.remote.UserFeignApi;
import com.wn.icloud.provider.uac.service.PermissionService;
import com.wn.icloud.provider.uac.service.UserBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author leeyang
 * @create 2017-06-21 8:15
 */
@RestController
@RequestMapping("/api")
public class UserRest implements UserFeignApi {

    @Autowired
    private PermissionService permissionService;

    @Autowired
    private UserBiz userBiz;

    //@Cache(key="permission")
    @Override
    @GetMapping(value = "/permissions")
    public List<PermissionInfo> getAllPermissionInfo() {
        return permissionService.getAllPermission();
    }

    //@Cache(key="permission:u{1}")
    @Override
    @GetMapping(value = "/user/un/{username}/permissions")
    public List<PermissionInfo> getPermissionByUsername(@PathVariable("username") String username) {
        return permissionService.getPermissionByUsername(username);
    }

    @PostMapping(value = "/user/validate")
    @Override
    public UserInfo validate(@RequestBody JwtAuthenticationRequest authenticationRequest) {
        return permissionService.validate(authenticationRequest.getUsername(),
                authenticationRequest.getPassword());
    }

    @GetMapping(value = "/api/user/getUserlist")
    @Override
    public TableResultResponse getUserlist(@RequestParam("page")  Integer page,@RequestParam("size")  Integer size){
        return userBiz.getUserlist(page,size);
    }

    @GetMapping(value = "/api/user/getUserInfo")
    @Override
    public UserInfo getUserInfo(@RequestParam("userid") Integer userid){
        return userBiz.getUserInfo(userid);
    }

}
